define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_realname/index' + location.search,
                    add_url: 'user_realname/add',
                    edit_url: 'user_realname/edit',
                    del_url: 'user_realname/del',
                    multi_url: 'user_realname/multi',
                    table: 'user_realname',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'user.mobile', title: __('User.mobile')},
                        {field: 'user.avatar', title: __('User.avatar'), operate: false,events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'truename', title: __('Truename')},
                        {field: 'card_num', title: __('Card_num')},
                        {field: 'zheng_image', title:'身份证正面',operate: false, events: Table.api.events.image,formatter: Table.api.formatter.image},
                        {field: 'fan_image', title:'身份证反面', operate: false,events: Table.api.events.image,formatter: Table.api.formatter.image},
                        {field: 'pay_image', title:'付款凭证',operate: false ,events: Table.api.events.image, formatter:function (value) {
                                if (value == '' || value == null){
                                    return "<span style='color: green'>预排期免费</span>";
                                }else{
                                    return '<a href="javascript:"><img class="' + 'img-sm img-center' + '" src="' + Fast.api.cdnurl(value) + '" /></a>';
                                }
                            }},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('审核'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [

                                {
                                    name: 'ajax',
                                    text: __('通过'),
                                    title: __('通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'user_realname/ok',
                                    confirm: '确认-通过',
                                    refresh:true,
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    },
                                    visible:function (row) {
                                        if (row.status == 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }
                                },
                                {
                                    name: 'ajax',
                                    text: __('驳回'),
                                    title: __('驳回'),
                                    classname: 'btn btn-xs btn-error btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'user_realname/no',
                                    confirm: '确认-驳回',
                                    refresh:true,
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    },
                                    visible:function (row) {
                                        if (row.status == 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});